<template>

    <div>
        <el-dialog :model-value="dialogVisible" title="企业权限" width="500" :close-on-click-modal="false" @close="cls">
            <el-form ref="ruleFormRef" style="max-width: 600px" :model="ruleForm" :rules="rules" label-width="auto"
                status-icon>
                <el-form-item label="可创建的员工数" prop="empNum" >
                    <el-input v-model="ruleForm.empNum"/>
                </el-form-item>

                <el-form-item label="可创建的账套数" prop="accountNum">
                    <el-input v-model="ruleForm.accountNum" />
                </el-form-item>

            </el-form>


            <template #footer>
                <div class="dialog-footer">
                    <el-button type="primary" @click="save">保存</el-button>
                    <el-button @click="cls">不保存关闭</el-button>
                </div>
            </template>
        </el-dialog>
    </div>

</template>

<script setup>
import {ref,reactive} from 'vue'
import { auth } from '@/api/platform/enterprise.js'
import { ElMessage } from "element-plus";
//属性

//表单对象
const ruleForm = ref({
    id:0,
    empNum:'',     //可创建的员工数
    accountNum:''  //可创建的账套数
})
//form表单引用
const ruleFormRef = ref(null)

//表单验证规则
const rules = reactive({
    empNum: [
        { required: true, message: '请输入可创建的员工数', trigger: 'blur' },
    ],
    accountNum: [
        { required: true, message: '请输入可创建的账套数', trigger: 'blur' },
    ]
})

//声明属性
const props = defineProps({
    "dialogVisible": {
        required: true,
        type: Boolean,
        default: false
    }
})

//声明事件
const emits = defineEmits(["close"]);

//方法区
let init = (id)=>{
    // console.log(id)
    ruleForm.value.id=id
    // console.log(ruleForm.value.id)
}

//暴露init方法
defineExpose({init})

//关闭
let cls = () => {
    //抛出事件
    emits("close")
}

//保存
let save = async()=>{
    //调用表单校验 异步的
    let valid = await ruleFormRef.value.validate(valid => { })
    if (!valid) {
        return;
    }
    // console.log(ruleForm.value);
    // return;

   
    //验证通过 发送请求 提交表单
    let res = await auth(ruleForm.value)
    if (res.code==200) {
        ElMessage({
            message: "保存成功",
            type: "success"
        });
        //关闭对话框
        cls();
    }
}
</script>

<style scope></style>